package com.yuanian.timingwheel.bootstrap;

import com.yuanian.timingwheel.facade.TwManager;
import com.yuanian.timingwheel.model.task.FixedDateTask;
import com.yuanian.timingwheel.model.task.IntervalTask;
import com.yuanian.timingwheel.model.timingwheel.DayTimingWheel;
import com.yuanian.timingwheel.test.Person;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.Date;

@Component
public class BootStrap implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {

        TwManager.getInstance().start();


        //测试
        DayTimingWheel dayTimeWheel = new DayTimingWheel();

        IntervalTask task = new IntervalTask(3, 1000000, "xxx");
        try {
            task.createTaskMethod("run", "person", new Object[]{"xxxx"});
        } catch (Exception e) {
            e.printStackTrace();
        }
        //dayTimeWheel.save(task);
       for (int j = 0; j < 40; j++) {
            for (int i = 0; i < 1000; i++) {
                Person p = new Person();
                FixedDateTask task1 = new FixedDateTask("1", new Date(new Date().getTime() + i*40 ), "sss");
                try {
                    task1.createTaskMethod("run", "person", new Object[]{"ssss"});
                } catch (Exception e) {
                    e.printStackTrace();
                }
                //dayTimeWheel.save(task1);
            }}
//
//             /*   FixedDateTask task = new FixedDateTask("1", i, "xxx");
//
//             /*   try {
//                    task.createTaskMethod("run", p, null);
//                    task.setTaskDesc(i + "");
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//                AttachTask attachTask = new AttachTask("附属任务");
//                try {
//                    attachTask.createTaskMethod("run", p, null);
//                    attachTask.setTaskDesc(i + "");
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }*/
//                //task.addAttachTask(attachTask);
//                //task.executionTime = new Date(System.currentTimeMillis() + i * 1000);
//                //dayTimeWheel.addTask(task);
//            }
//            //}
//
//
//        }





      /*  try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        dayTimeWheel.start();*/

    }
}
